import * as Cesium from 'cesium';

class DrawPlane {
  constructor(viewer, arr = [110, 40, 0]) {
    this.viewer = viewer;
    this.planePrimitive = null;
    this.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(Cesium.Cartesian3.fromDegrees(arr[0], arr[1], arr[2]));
    this.planePosition = [110.0001, 40.000, 110.005, 40.002]
    this.intervalRows = 10;
    this.intervalColumns = 10;
  }
  drawPlane (height) {
    var positions = Cesium.Cartesian3.fromDegreesArrayHeights([
      110.001, 40.000, height,
      // 110.002, 40.000, height,
      // 110.003, 40.000, height,
      // 110.004, 40.000, height,
      110.005, 40.000, height,
      110.005, 40.002, height,
      // 110.004, 40.002, height,
      // 110.003, 40.002, height,
      // 110.002, 40.002, height,
      110.001, 40.002, height,
      110.001, 40.000, height,
    ]);
    // 定义顶点坐标（相对于中心点的偏移量）
    var relativePositions = Cesium.Cartesian3.fromDegreesArray([0, 0, 1, 0, 1, 1, 0, 1, 0, 0]);
    // 创建Geometry对象
    var geometry = new Cesium.PolylineGeometry({
      positions: positions,
      width: 1.0,
      vertexFormat: Cesium.VertexFormat.ALL
    });
    // 创建Appearance对象
    var appearance = new Cesium.PolylineMaterialAppearance({
      material: Cesium.Material.fromType('Color', {
        color: Cesium.Color.WHITE
      })
    });
    // 创建Primitive对象
    this.planePrimitive = new Cesium.Primitive({
      geometryInstances: new Cesium.GeometryInstance({
        geometry: geometry,
        // modelMatrix: this.modelMatrix
      }),
      appearance: appearance,
      primitiveType: Cesium.PrimitiveType.LINES
    });
    this.viewer.scene.primitives.add(this.planePrimitive);
  }
}

export default DrawPlane;